package com.Bride.smarthome.controller.admin.Device;


import com.Bride.common.core.domain.R;
import com.Bride.common.core.web.controller.BaseController;
import com.Bride.smarthome.service.Device.DeviceControlService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 设备控制管理控制器
 *
 *   2025/9/8
 *   com.Bride.smarthome.controller.admin.Device
 *   @author winkin
 * */

@Tag(name = "管理后台 - 设备控制管理", description = "设备控制管理接口")
@RestController
@RequestMapping("/admin/device/control")
public class DeviceControlController extends BaseController {

    @Autowired
    private DeviceControlService deviceControlService;

    /**
     * 打开设备
     */
    @Operation(summary = "打开设备")
    @PostMapping("/turnOn/{deviceId}")
    public R turnOn(@PathVariable("deviceId") Long deviceId) {
        boolean success = deviceControlService.turnOn(deviceId);
        if (success) {
            return R.ok("设备已打开");
        } else {
            return R.fail("操作失败");
        }
    }

    /**
     * 关闭设备
     */
    @Operation(summary = "关闭设备")
    @PostMapping("/turnOff/{deviceId}")
    public R turnOff(@PathVariable("deviceId") Long deviceId) {
        boolean success = deviceControlService.turnOff(deviceId);
        if (success) {
            return R.ok("设备已关闭");
        } else {
            return R.fail("操作失败");
        }
    }

    /**
     * 设置设备状态
     */
    @Operation(summary = "设置设备状态")
    @PostMapping("/status/{deviceId}")
    public R setStatus(@PathVariable("deviceId") Long deviceId, @RequestParam("status") String status) {
        boolean success = deviceControlService.setStatus(deviceId, status);
        if (success) {
            return R.ok("状态设置成功");
        } else {
            return R.fail("操作失败");
        }
    }
}
